package com.example.myapplication.observers;

import com.example.myapplication.entity.ResMsg;
import com.example.myapplication.entity.User;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @author sjh
 * @Description
 * @create 2022/3/9 16:34
 */
public abstract class LoginObserver implements Observer<ResMsg> {

    public abstract void success(User user);

    public abstract void error(String message);

    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(ResMsg resMsg) {
        if (resMsg.getCode() == 200) {
            success((User) resMsg.getData());
        } else {
            error(resMsg.getMessage());
        }
    }

    @Override
    public void onError(Throwable e) {
        error(e.getMessage());
    }

    @Override
    public void onComplete() {

    }
}
